<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>汽车管理</title>
		 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, minimal-ui">
         <meta name="apple-mobile-web-app-capable" content="yes">
         <meta content="yes" name="apple-touch-fullscreen">
         <meta name="apple-mobile-web-app-status-bar-style" content="black">  
         <script src="js/add_js.js"></script>
	</head>
    <body>
    	<!--nav-->
        <nav class="bar bar-tab">
             <a class="tab-item external active" href="home.html">我的</a>
             <a class="tab-item external" href="order.html">定单</a>
             <a class="tab-item external" href="carRental.html">发布</a>
             <a class="tab-item external" href="rentalCar.html">租用</a>
         </nav>
    <!--nav-->
       <div class="page content">
       	<header class="bar bar-nav">
               
               <a  class="button button-link button-nav pull-right active">车辆管理</a>
               <a href="home.html" class="button button-link button-nav pull-right">返回我的账户 </a>
            </header>
      	<!--<header class="bar bar-nav">
          <h1 class="title">登陆</h1>
        </header>-->
      		<div class="carManger-list">
      			<ul>
      				<!--车辆信息列表-->
      			</ul>
      			<div class="carManger-list-add">
      				<div><a href="checkCar.html"><img src="img/icon/j.png">添加一部车</a></div>
      			</div>
      	    </div>
      	    <script>
      	    $(document).ready(function(){
      	    	if(my.checkLogin()){
      	    		my.scollToggleBar()
      	        //my.checkLogin()
      	        $.showIndicator()
      	        //key=my.get_key(sessionStorage.token)
      	        key=my.get_key(my.getCookie('token'))
      	        var r_check_id=null
      	        var info={
      						//'u_userid':sessionStorage.id,
      						'u_userid':my.getCookie('id'),
      					}
    				info=JSON.stringify(info)
                    info=my.cryptoASEencrypt(info,key).toString()
      	            $.ajax({
      						type:"post",
      						url:"http://192.168.1.10:8082/index.php?r=userabout%2Fuser%2Fusercarlist",
      						data:{
      							'api_value':info
      						},
      						async:true,
      						error:function(){
      							$.hideIndicator()
      							$.toast("请求失败，请刷新重试");
      						},
      						success:function(data){
      							if(data.match("err_code")!=null){
      								$.hideIndicator()
      								switch(JSON.parse(data).err_code)
      								{
      									case 40003:
      									    my.tokenExpire()
      									   break;
      									default:
      									   $.toast(JSON.parse(data).err_msg);
      									   
      								}
                                         
      							}else{
      								    
      								    data=JSON.parse(my.cryptoASEdencrypt(data,key))
      								    //循环输出车辆
      								    for(i=0;i<data.length;i++){
      								     var none='display:none;';
      								     var none_in='display:none'
      								     var none_edit='display:none'
      								     var state_doc='...正在认证'
      								     if(data[i].auditresult_state==1){
      								     	none='display:block;'
      								     	none_in='display:inline-block;'
      								     	state_doc='认证通过'
      								     }
      								     if(data[i].auditresult_state==2){
      								     	none_edit='display:block'
      								     	state_doc='认证失败：'+data[i].resultreason
      								     }
      								      var list='<li name="'+ data[i].usercar_id +'"><div class="car-edit"><div class="carManger-list-top"><div><span><img src="img/icon/qcc.png" ></span><p class="brand_chinese_name">'
      					                                      + data[i].brand_chinese_name +'</p><div class="clear"></div></div><div class="car_plate">'
      					                                      + data[i].car_plate +'</div><div class="auditresult_state"><img src="img/icon/ok.png" style="width:15px;margin: 0 5px -2px 0;'+ none_in +'">'
      					                                      + state_doc +'</div></div></div><div class="carManger-list-btn" style="'+ none +'"><div><img src="img/icon/rll.png">出租</div><div class="clear"></div></div><div class="carManger-list-btn carManger-list-btn-edit" style="'+ none_edit +'"><div class="r-check open-popup"><img src="img/icon/bj.png">重新认证</div><div class="clear"></div></div></li>'
      								      $('.carManger-list ul').append(list)	
      								    }
      								    $.hideIndicator()
      								    //删除汽车
//    								    $('.delete-car').click(function(){
//    					                   var cars_id=$(this).closest('li').attr('name')
//    					                      $.confirm('确认要删除么', function () {
//    					                      	$.showIndicator()
//    					                      	var info={
//    						                          // 'u_userid':sessionStorage.id,
//    						                           'u_userid':my.getCookie('id'),
//    						                           'cars_id':cars_id,
//    					                              }
//  					                            info=JSON.stringify(info)
//  					                            console.log(info)
//                                                  info=my.cryptoASEencrypt(info,key).toString()
//    					                            $.ajax({
//    						                        type:"post",
//    						                        url:"http://192.168.1.10:8082/index.php?r=userabout%2Fuser%2Fusercardelete",
//    						                        data:{
//    							                       'api_value':info,
//    						                           },
//    						                        async:true,
//    						                        error:function(){
//    							                                    $.hideIndicator()
//    							                                    $.toast("删除失败，请重试");
//    							                                    //$.router.reloadPage()
//    						                                      },
//    						                        success:function(data){
//    							                        if(data.match("err_code")!=null){
//    								                     $.hideIndicator()
//    								                     switch(JSON.parse(data).err_code)
//    								                     {
//    									                   case 40003:
//    									                    my.tokenExpire()
//    									                   break;
//    									                  default:
//    									                    $.toast(JSON.parse(data).err_msg);
//    									                    //$.router.reloadPage()
//    								                     }
//                                       
//    							                         }else{
//      								               
//      								                 	$('[name='+cars_id+']').css('display','none')
//      								                 	$.hideIndicator()
//      								                 	$.toast('删除成功')
//                                                        }
//    					                         	},
//    					                           });
//                                             });
//    				                        })
      							          }
      							        //汽车编辑
      							        $('.car-edit').click(function(){
      							        	sessionStorage.car_id=$(this).closest('li').attr('name')
      							        	$.router.loadPage('carEdit.html')
      							        })
      							        //重新认证
      							        
      							        $('.r-check').click(function(){
      							         r_check_id=$(this).closest('li').attr('name')
      							        })
      							        
      			                    },		            
      		                    });
      		                    //重新认证上传图片
      			                      $('.img-xsz-z').click(function(){
      				                     ad.native_get_photo('.img-xsz-z')
      			                      })
      			                      $('.img-xsz-f').click(function(){
      				                      ad.native_get_photo('.img-xsz-f')
      			                      })
      			                        $('.img-jqx').click(function(){
      				                    ad.native_get_photo('.img-jqx')
      			                       })
      			                       $('.img-syx').click(function(){
      				                   ad.native_get_photo('.img-syx')
      			                        })
      		                     //重新认证表单
      		                      $('.r-check-btn').click(function(){
      				             for(i=0;i<$('.update-car-details-list :text').length;i++){
      					            if($('.update-car-details-list :text').eq(i).val()==''){
      						        $('.update-car-details-list :text').eq(i).focus()
      						     return false
      					             }
      				             }
      				           
      				            $.showIndicator()
      				        var info={
      						//'u_userid':sessionStorage.id,
      						'u_userid':my.getCookie('id'),
      						'cars_id':r_check_id,
      						'c_number':$('[name=c_number]').val(),
      						'insurance_num':$('[name=insurance_num]').val(),
      						'busin_num':$('[name=busin_num]').val(),
      						'veh_first_img':$('.img-xsz-z').attr('name'),
      						'veh_second_img':$('.img-xsz-f').attr('name'),
      						'insurance_img':$('.img-jqx').attr('name'),
      						'busin_img':$('.img-syx').attr('name'),
      					}
    					info=JSON.stringify(info)
    					console.log(info)
    					$('.carManger-list-add').text(info)
                        info=my.cryptoASEencrypt(info,key).toString()
      				    $.ajax({
      						type:"post",
      						url:"http://192.168.1.10:8082/index.php?r=userabout%2Fuser%2Fupdatecaridentity",
      						data:{
      							'api_value':info
      						},
      						async:true,
      						error:function(){
      							$.hideIndicator()
      							$.toast("提交失败，请重试..");
      						},
      						success:function(data){
      							if(data.match("err_code")!=null){
      								$.hideIndicator()
      								switch(JSON.parse(data).err_code)
      								{
      									case 40003:
      									    my.tokenExpire()
      									   break;
      									default:
      									   $.toast(JSON.parse(data).err_msg);
      								}
                                         
      							}else{
      								    $.hideIndicator()
      								    //data=JSON.parse(my.cryptoASEdencrypt(data,key))
        								$.toast("提交成功，等待审核");
      							        $.router.reloadPage();
      							}
      						},
      				});
      						
      			})
      		      //重新认证结束
      		   
      		   }
      		})
      	    </script>
      	</div>
      	<div class="update-car-details-list popup">
      				      <input type="text" name='c_number' placeholder="车牌号码" />
      				      <input type="text" name='insurance_num' placeholder="交强险保单号" />
      				      <input type="text" name='busin_num' placeholder="商业险保单号" />
      				      <div class="img-xsz-z">上传行驶证正本照片</div>
      				      <div class="img-xsz-f">上传行驶证副本照片</div>
      				      <div class="img-jqx">上传交强险保单照片</div>
      				      <div class="img-syx">上传商业险保单照片</div>
      				      <div style="border: none;"><a class="bottn r-check-btn" id="dl">提交</a><a class="bottn close-popup">取消</a></div>
      	</div>
	</body>
</html>